package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 *购物车接口
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 动态条件查询
     * @param shoppingCart
     * @return
     */

    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 修改购物车数据
     * @param cart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart set name = #{name}, image = #{image}, user_id = #{userId}, dish_id = #{dishId}, " +
            "setmeal_id = #{setmealId}, dish_flavor = #{dishFlavor}, amount = #{amount}, number = #{number}, create_time = #{createTime}")
    void insert(ShoppingCart shoppingCart);

    /**
     * 删除购物车一个商品
     * @param shoppingCart
     */
    //sql: delete from shopping_cart where user_id = #{userId} and dish_id = #{dishId} and setmeal_id = #{setmealId} and dish_flavor = #{dishFlavor}
    void deleteByID(ShoppingCart shoppingCart);

    /**
     * 批量插入购物车数据
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
